/**
 * @author:fangxiaohua
*  @邮箱：abc2710712@qq.com
*  @qq:1295168875
*   用户业务操作操作
*/
void(function(exports){
	//数据库操作
	var dbLib = require('../lib/dbLib');
	//工具类模块
	var tools = require('../lib/toolsLib');
	
	//意见反馈列表
	exports.list = function(req, res){
		var pageNo=req.body.pageNo;
		var pageSize=req.body.pageSize;
		var q=req.body.q;
		var status=req.body.status;
		var  sql=["select f.id,f.content,f.contact,f.submit_time,f.status from t_feedback f where f.content like ? ",
		          		status!="2"?" and f.status=? ":"",
		          		" order by f.submit_time desc"].join("");
		q=q==null?"%%":"%"+q+"%";
		var params=[q,status];
		dbLib.dbPageQuery(sql,pageNo,pageSize,params,function(err,result){
			res.send(result);
			return;
		});
	};
	
	//标记意见反馈已读
	exports.read = function(req, res){
		var id=req.body.id;
		var sql="update t_feedback f set f.status=1 where f.id=?";
		var params=[id];
		dbLib.dbUpdate(sql,params,function(err,result){
			if(err){
				res.send("false");
				return;
			}
			res.send("true");
			return;
		});
	};
	
	//添加吐槽
	exports.add=function(req,res){
		var content=req.body.content;
		var contact=req.body.contact;
		var sql="insert into  t_feedback (content,contact,submit_time,status) values(?,?,now(),0)";
		var params=[content,contact];
		dbLib.dbAdd(sql,params,function(err,result){
			if(err){
				res.send("false");
				return;
			}
			res.send("true");
			return;
		});
	}
	
	
})( (function(){
    if(typeof exports === 'undefined') {
        window.exports = {};
        return window.exports;
    } else {
        return exports;
    }
})());